<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="${ bp }/static/img/icon.png" type="image/x-icon">
    <link rel="stylesheet" href="${ bp }/static/layui/css/layui.css">

</head>

<body>
<%--修改表单--%>
<div class="layui-container" >

    <form class="layui-form " style="margin-top: 30px">
        <div class="layui-form-item layui-hide">
            <label class="layui-form-label">id</label>
            <div class="layui-input-block">
                <input type="text" name="id" value="${user.id}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" value="${user.username}" lay-verify="required" lay-reqText="用户名不能为空" autocomplete="off" placeholder="请输入用户名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" value="${user.password}" lay-verify="required" lay-reqText="密码不能为空"  autocomplete="off" placeholder="请输入密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" value="${user.email}" lay-verify="required" lay-reqText="邮箱不能为空"  autocomplete="off" placeholder="请输入邮箱" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">余额</label>
            <div class="layui-input-block">
                <input type="text" name="account" value="${user.account}" autocomplete="off" placeholder="请输入余额" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">积分</label>
            <div class="layui-input-block">
                <input type="text" name="credit" value="${user.credit}" autocomplete="off" placeholder="请输入积分" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-input-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-checked " lay-submit lay-filter="update">修改</button>
                <button type="reset" class="layui-btn layui-btn-danger">重置</button>
            </div>
        </div>
    </form>


</div>


<!-- layui.all.js 包含layui核心库和所有组件 -->
<script src="${ bp }/static/layui/layui.all.js"></script>
<script>
    // Layui遵循模块化开发思想，所有的功能模块，原则上在使用之前都需要声明
    layui.use(['form', 'layer', 'jquery'], function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;


        //监听修改表单提交
        form.on('submit(update)',function (data){
            //获取请求参数
            let addParams=data.field;

            $.ajax({
                url:'${bp}/useradmin?method=update',
                type:'post',
                data:addParams,
                dataType:'json',
                success:(result)=>{
                    // 判断是否修改成功
                    if (result.code === 0) {
                        // 成功信息提示
                        layer.msg('修改成功', {
                            time: 1000
                        }, function () {
                            //关闭弹窗
                            //先得到当前iframe层的索引
                            let index = parent.layer.getFrameIndex(window.name)
                            //再执行关闭
                            parent.layer.close(index);
                            //刷新对应模块的table
                            parent.document.getElementById('用户数据').layui.table.reload('table');
                        });
                    } else {
                        // 错误信息提示
                        layer.msg(result.msg, {
                            time: 2000,
                            icon: 2
                        });
                    }
                },
                error:()=>{
                    console.log('请求接口错误');
                }
            })

        });

    });
</script>

</body>
</html>
